<?php
/**
 * 多进程执行
 * User: dxk
 * Date: 2020/08/05
 */
namespace App\Console\Commands\Core;

use App\Service\Core\Service\Queue\QueueMapService;
use Illuminate\Console\Command;

class QueueMonitor extends Command
{
    protected $signature = 'Core:QueueMonitor {queue}';
    protected $description = '平台队列监控';

    public function handle()
    {
        $queue = trim($this->argument('queue'));
        if (empty($queue)) {
            $this->info('请设置要执行的队列名');
            die;
        }
        $handle_class = QueueMapService::$map[$queue];
        if (!isset($handle_class)) {
            $this->info($this->signature . '不支持的队列服务' . $handle_class);
            die;
        }
        $handle_obj = new $handle_class();
        if (!is_string($handle_class) || !is_callable([$handle_obj, 'main'])) {
            $this->info($this->signature . '队列对应的处理类不可用' . $handle_class . ':main');
            die;
        }
        //主进程
        call_user_func([$handle_obj, 'main']);
    }
}
